<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>register</p>
    <form>
        <input type="text" placeholder="phone" class="phone">
        <br>
        <input type="text" placeholder="code" value="r2b7" class="code">
        <br>
        <input type="text" placeholder="username" class="username">
        <br>
        <input type="password" placeholder="password" class="password">
        <br>
        <button type="button" class="register">register</button>
    </form>
    <hr>
    <hr>
    <hr>
    <p>login</p>
    <form>
        <input type="text" placeholder="phone" class="phone1" value="18937366671">
        <br>
        <input type="text" placeholder="code" value="r2b7" class="code1">
        <br>
        <input type="text" placeholder="username" value="qwer1" class="username1">
        <br>
        <input type="password" placeholder="password" value="123abcd" class="password1">
        <br>
        <button type="button" class="login">login</button>
    </form>
    <script src="../0505/js/jq.js"></script>
    <script>
        $(function(){

            // 注册
            $('.register').click(function() {
                var info = {
                    phone: $('.phone').val(),
                    code: $('.code').val(),
                    username: $('.username').val(),
                    password: $('.password').val(),
                };
                // console.log(info);
                $.ajax({
                    url: 'http://localhost:3000/users/register',
                    type: 'post',
                    data: info,
                    success: function(data) {
                        console.log(data);
                    }
                })
            })

            // 登陆
            $('.login').click(function() {
                var info = {
                    phone: $('.phone1').val(),
                    code: $('.code1').val(),
                    username: $('.username1').val(),
                    password: $('.password1').val(),
                };
                $.ajax({
                    url: 'http://localhost:3000/users/login',
                    type: 'post',
                    data: info,
                    success: function(res) {
                        console.log(res);
                    }
                })
            })

        })
    </script>
</body>
</html>